package com.zmn.oms.task.es.business.impl.ordercomment;

import com.zmn.comment.common.dro.cmt.CommentMessageDRO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.oms.services.interfaces.datasync.ElasticSearchDataSyncService;
import com.zmn.oms.services.interfaces.order.OrderChangeService;
import com.zmn.oms.task.es.business.interfaces.ordercomment.SyncEsOrderCommentBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 类描述：同步订单评价实现
 *
 * @author lujia
 * @date 2018/11/23 19:38
 */
@Service
public class SyncEsOrderCommentBServiceImpl implements SyncEsOrderCommentBService {

    @Autowired
    private ElasticSearchDataSyncService elasticSearchDataSyncService;
    @Autowired
    private OrderChangeService orderChangeService;

//     @Override
//     public void sync(Long orderId) {
//
//         logger.info("#ordercommentchange#sync start orderid : {}", orderId);
//
//         if (Objects.isNull(orderId)) {
//             return;
//         }
//
//         elasticSearchDataSyncService.(Lists.newArrayList(orderId));
//         orderChangeService.changeSyncToMos(orderId);
//
// //        logger.info("cmtCommentListRemoteService.getOrderCommentByOrderId params={}", orderId);
// //        ResponseDTO<CommentDetailDRO> commentDro = cmtCommentListRemoteService.getCommentByOrderId(orderId);
// //        logger.info("cmtCommentListRemoteService.getOrderCommentByOrderId result={}", commentDro);
// //        if (!commentDro.isSuccess() || Objects.isNull(commentDro.getData())) {
// //            return;
// //        }
// //        OrderWork orderWorkDb = orderWorkService.findOrderWorkByKey(orderId, orderId);
// //        EsOrderWork esOrderWork = getSyncCommentInfoEsOrderWork(commentDro.getData(), orderWorkDb);
// //        if (Objects.isNull(esOrderWork)) {
// //            return;
// //        }
// //        esOrderWorkService.save(esOrderWork);
//     }

    @Override
    public void sync(List<CommentMessageDRO> commentMessageDROS) {
        if (CollectionUtil.isNullOrEmpty(commentMessageDROS)) {
            return;
        }

        List<Long> orderIdList = commentMessageDROS.stream().map(CommentMessageDRO::getOrderId).collect(Collectors.toList());
        elasticSearchDataSyncService.syncWorkIndex(orderIdList);
        for (Long orderId : orderIdList) {
            orderChangeService.changeSyncToMos(orderId);
        }
    }
}